package mini.memory;

import mini.expr.Element;

/**
 * Memory cell
 * 
 * @author anthony
 *
 */
public class ConsCell {
    private Element car;
    private ConsCell cdr;
    private boolean marked;
    private int address;
    
    public ConsCell() {}

    public Element getCar() {
        return car;
    }

    public void setCar(Element car) {
        if (car == null) {
            throw new IllegalArgumentException("Car field cannot be null.");
        }
        
        this.car = car;
    }

    public ConsCell getCdr() {
        return cdr;
    }

    public void setCdr(ConsCell cdr) {
        this.cdr = cdr;
    }

    public boolean isList() {
        return car.isList();
    }

    public boolean isMarked() {
        return marked;
    }

    public void setMarked(boolean marked) {
        this.marked = marked;
    }

    public int getAddress() {
        return address;
    }

    public void setAddress(int address) {
        this.address = address;
    }
    
    public String toString() { 
    	return "[CONS marked=" + (marked ? "T" : "F") + ", address=" + address + ", element=" + car + ", cdr=" + cdr + "]";
    }
}
